function getFirst(num) {
  let length = Math.ceil(num.length / 4)
  let first = num.length % 4 === 0 ? 4 : num.length % 4
  let explain = ''
  let hasAdd = false
  let canAdd = hasZero(num)

  for (let i = 0; i < length; i++) {
    hasAdd = explain.indexOf('零') > -1
    let cur = num.substring(first + (i - 1) * 4, first + i * 4)
    let str = getChina(cur, length - i, canAdd, hasAdd)
    explain += str
  }
  return explain
}

function getNext(num) {
  let explain = ''
  let chinaArr = ['壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
  if (Number(num) === 0) {
    explain += '整'
  } else {
    let arr = num.split('')
    let index = 0
    for (let i of arr) {
      if (Number(i) !== 0) {
        if (index === 0) {
          explain += chinaArr[Number(i) - 1] + '角'
        } else if (index === 1) {
          explain += chinaArr[Number(i) - 1] + '分'
        }
      }
      index++
    }
  }
  return explain
}

function getChina(num, stage, canAdd, hasAdd) {
  let chinaArr = ['壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
  let arr = num.split('')
  let str = ''
  let step = arr.length
  for (let i of arr) {
    if (Number(i) !== 0) {
      if (step === 4) {
        str += chinaArr[Number(i) - 1] + '仟'
      } else if (step === 3) {
        str += chinaArr[Number(i) - 1] + '佰'
      } else if (step === 2) {
        if (Number(i) - 1 !== 0) {
          str += chinaArr[Number(i) - 1] + '拾'
        } else {
          str += '拾'
        }
      } else if (step === 1) {
        str += chinaArr[Number(i) - 1]
      }
    } else {
      if (canAdd && !hasAdd) {
        str += '零'
        hasAdd = true
      }
    }
    step--
  }

  if (stage % 3 === 0) {
    str += '亿'
  } else if (stage % 3 === 2) {
    str += '万'
  }

  str = str.replace('零万', '万零')
  return str
}

function hasZero(num) {
  let flag = false
  if (num.length === 1) {
    flag = false
  } else {
    flag = num.includes('0')
  }
  return flag
}

let inputs = ['151121.15', '10012.02', '13.64', '0.85']
let line
while ((line = inputs.shift())) {
  let numArr = line.split('.')
  console.log(line, numArr)
  let first = getFirst(numArr[0])
  console.log(first)
  let next = getNext(numArr[1])
  let hasYuan =
    numArr[0].length > 1 || (numArr[0].length === 1 && Number(numArr[0]) !== 0)
  console.log(`人民币${first}${hasYuan ? '元' : ''}${next}`)
}
